// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include <map>
#include "ObjLoader.generated.h"
class FMeshDescriptionBuilder;

UCLASS()
class CLASS08_API AObjLoader : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AObjLoader();
	
	UPROPERTY(VisibleAnywhere)
	UStaticMeshComponent* _mesh;

	UStaticMesh* CreateMeshDataFromFile(const FString& baseDir, const FString& file);
	UTexture2D* CreateTexture(const FString& baseDir, const FString& file);

	struct GlobalData
	{
		FMeshDescriptionBuilder* builder;
		TArray<FVertexID> vertexIDs;
		FPolygonGroupID polygonGroup;
	};

	struct TriangleVertex
	{
		int vertexIndex;
		FVector instanceNormal;
		FVector2D instanceUV;
	};
	void AddTriangleData(GlobalData& globalData, const TriangleVertex& v1,
		                 const TriangleVertex& v2, const TriangleVertex& v3);

protected:
	virtual void BeginPlay() override;

	std::map<FPolygonGroupID, std::string> _materialIdMap;
	std::map<std::string, UMaterialInstanceDynamic*> _materialMap;
};
